{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "893324a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "model = ChatOpenAI(\n",
    "                    model=\"qwen-plus\",\n",
    "                    openai_api_key=\"sk-33e537a7aa4c4ae29807740a802d0b68\",\n",
    "                    openai_api_base=\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\n",
    "                    temperature=0.1,\n",
    "                    timeout=120,  # 增加超时时间到120秒\n",
    "                    max_retries=2  # 添加重试\n",
    "                )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dc20718a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "content='你好呀！✨ 很高兴见到你！今天过得怎么样呀？希望你度过了愉快的一天。我随时准备好陪你聊天、帮你解决问题，或者就这样轻松愉快地闲聊一会儿。有什么想跟我分享的吗？ 🌟' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 51, 'prompt_tokens': 13, 'total_tokens': 64, 'completion_tokens_details': None, 'prompt_tokens_details': {'audio_tokens': None, 'cached_tokens': 0}}, 'model_name': 'qwen-plus', 'system_fingerprint': None, 'id': 'chatcmpl-0aa5dae4-a648-9401-96b1-5fa6d24670bb', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None} id='run--3ed4f826-427a-44f2-b878-7ebef98d0dac-0' usage_metadata={'input_tokens': 13, 'output_tokens': 51, 'total_tokens': 64, 'input_token_details': {'cache_read': 0}, 'output_token_details': {}}\n"
     ]
    }
   ],
   "source": [
    "message = model.invoke(\"你好\")\n",
    "print(message)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6a0ce571",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3020e07b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd000bb4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
